package routers

import (
	"github.com/gin-gonic/gin"
	"gotest/src/modles"
	"gotest/src/service"
	"log"
	"net/http"
)

// @Summary 保存用户信息
// @Produce  json
// @Param user body modles.TestUser true "用户数据实体"
// @Success 200
// @Failure 500
// @Router /insertUser [post]
func InsertUser(c *gin.Context) {
	var pperson modles.TestUser
	err := c.BindJSON(&pperson)
	if err != nil {
		c.JSON(200, gin.H{"errcode": 400, "description": "Post Data Err"})
		return
	} else {
		log.Println("转换后的对象内容:", pperson)
	}
	ids, err := service.InsertUserPost(pperson)
	if err != nil {
		c.JSON(200, gin.H{"errcode": 400, "description": err.Error()})
		return
	}
	c.JSON(http.StatusOK, gin.H{"errcode": 200, "data": ids})
}

func InsertUser22(pperson modles.TestUser) string {

	ids, err := service.InsertUserPost22(pperson)
	if err != nil {
		return ""
	}
	return ids
}
